package com.hamizhong.iflowers.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.springframework.beans.BeanUtils;

import com.hamizhong.iflowers.db.dao.hibernate.IColorDao;
import com.hamizhong.iflowers.db.dao.hibernate.IFestivalDao;
import com.hamizhong.iflowers.db.dao.hibernate.IFlowerCountDao;
import com.hamizhong.iflowers.db.dao.hibernate.IFlowerFloridDao;
import com.hamizhong.iflowers.db.dao.hibernate.IGoodsDao;
import com.hamizhong.iflowers.db.dao.hibernate.IGoodsFestivalMapDao;
import com.hamizhong.iflowers.db.dao.hibernate.IGoodsProductMapDao;
import com.hamizhong.iflowers.db.dao.hibernate.IGoodsPurposeMapDao;
import com.hamizhong.iflowers.db.dao.hibernate.IGoodsTargetMapDao;
import com.hamizhong.iflowers.db.dao.hibernate.IProductDao;
import com.hamizhong.iflowers.db.dao.hibernate.IPurposeDao;
import com.hamizhong.iflowers.db.dao.hibernate.ITargetDao;
import com.hamizhong.iflowers.db.dao.hibernate.IVarietyDao;
import com.hamizhong.iflowers.db.entity.Color;
import com.hamizhong.iflowers.db.entity.Festival;
import com.hamizhong.iflowers.db.entity.FlowerCount;
import com.hamizhong.iflowers.db.entity.FlowerFlorid;
import com.hamizhong.iflowers.db.entity.Goods;
import com.hamizhong.iflowers.db.entity.GoodsFestivalMap;
import com.hamizhong.iflowers.db.entity.GoodsProductMap;
import com.hamizhong.iflowers.db.entity.GoodsPurposeMap;
import com.hamizhong.iflowers.db.entity.GoodsTargetMap;
import com.hamizhong.iflowers.db.entity.Product;
import com.hamizhong.iflowers.db.entity.Purpose;
import com.hamizhong.iflowers.db.entity.Target;
import com.hamizhong.iflowers.db.entity.Variety;
import com.hamizhong.iflowers.service.IGoodsService;
import com.hamizhong.iflowers.service.base.MyBaseService;
import com.hamizhong.iflowers.utils.MyErrorMsgConstants;
import com.hamizhong.iflowers.web.dto.IOPResultDto;
import com.hamizhong.iflowers.web.vo.ColorVO;
import com.hamizhong.iflowers.web.vo.FestivalVO;
import com.hamizhong.iflowers.web.vo.FlowerCountVO;
import com.hamizhong.iflowers.web.vo.FlowerFloridVO;
import com.hamizhong.iflowers.web.vo.GoodsFestivalMapVO;
import com.hamizhong.iflowers.web.vo.GoodsProductMapVO;
import com.hamizhong.iflowers.web.vo.GoodsPurposeMapVO;
import com.hamizhong.iflowers.web.vo.GoodsTargetMapVO;
import com.hamizhong.iflowers.web.vo.GoodsVO;
import com.hamizhong.iflowers.web.vo.IObjectVO;
import com.hamizhong.iflowers.web.vo.ProductVO;
import com.hamizhong.iflowers.web.vo.PurposeVO;
import com.hamizhong.iflowers.web.vo.TargetVO;
import com.hamizhong.iflowers.web.vo.VarietyVO;

public class GoodsServiceImpl extends MyBaseService implements IGoodsService {
	
	private IGoodsDao iGoodsDao = null;
	private IProductDao iProductDao = null;
	private IVarietyDao iVarietyDao = null;
	private IColorDao iColorDao = null;
	private IFlowerFloridDao iFlowerFloridDao = null;
	private IFlowerCountDao iFlowerCountDao = null;
	private IGoodsProductMapDao iGoodsProductMapDao = null;
	private IGoodsPurposeMapDao iGoodsPurposeMapDao = null;
	private IGoodsFestivalMapDao iGoodsFestivalMapDao = null;
	private IGoodsTargetMapDao iGoodsTargetMapDao = null;
	private IPurposeDao iPurposeDao = null;
	private IFestivalDao iFestivalDao = null;
	private ITargetDao iTargetDao = null;

	public IGoodsDao getiGoodsDao() {
		return iGoodsDao;
	}
	public void setiGoodsDao(IGoodsDao iGoodsDao) {
		this.iGoodsDao = iGoodsDao;
	}
	public IProductDao getiProductDao() {
		return iProductDao;
	}
	public void setiProductDao(IProductDao iProductDao) {
		this.iProductDao = iProductDao;
	}
	public IVarietyDao getiVarietyDao() {
		return iVarietyDao;
	}
	public void setiVarietyDao(IVarietyDao iVarietyDao) {
		this.iVarietyDao = iVarietyDao;
	}
	public IColorDao getiColorDao() {
		return iColorDao;
	}
	public void setiColorDao(IColorDao iColorDao) {
		this.iColorDao = iColorDao;
	}
	public IFlowerFloridDao getiFlowerFloridDao() {
		return iFlowerFloridDao;
	}
	public void setiFlowerFloridDao(IFlowerFloridDao iFlowerFloridDao) {
		this.iFlowerFloridDao = iFlowerFloridDao;
	}
	public IFlowerCountDao getiFlowerCountDao() {
		return iFlowerCountDao;
	}
	public void setiFlowerCountDao(IFlowerCountDao iFlowerCountDao) {
		this.iFlowerCountDao = iFlowerCountDao;
	}
	public IGoodsProductMapDao getiGoodsProductMapDao() {
		return iGoodsProductMapDao;
	}
	public void setiGoodsProductMapDao(IGoodsProductMapDao iGoodsProductMapDao) {
		this.iGoodsProductMapDao = iGoodsProductMapDao;
	}
	public IGoodsPurposeMapDao getiGoodsPurposeMapDao() {
		return iGoodsPurposeMapDao;
	}
	public void setiGoodsPurposeMapDao(IGoodsPurposeMapDao iGoodsPurposeMapDao) {
		this.iGoodsPurposeMapDao = iGoodsPurposeMapDao;
	}
	public IGoodsFestivalMapDao getiGoodsFestivalMapDao() {
		return iGoodsFestivalMapDao;
	}
	public void setiGoodsFestivalMapDao(IGoodsFestivalMapDao iGoodsFestivalMapDao) {
		this.iGoodsFestivalMapDao = iGoodsFestivalMapDao;
	}
	public IGoodsTargetMapDao getiGoodsTargetMapDao() {
		return iGoodsTargetMapDao;
	}
	public void setiGoodsTargetMapDao(IGoodsTargetMapDao iGoodsTargetMapDao) {
		this.iGoodsTargetMapDao = iGoodsTargetMapDao;
	}
	public IPurposeDao getiPurposeDao() {
		return iPurposeDao;
	}
	public void setiPurposeDao(IPurposeDao iPurposeDao) {
		this.iPurposeDao = iPurposeDao;
	}
	public IFestivalDao getiFestivalDao() {
		return iFestivalDao;
	}
	public void setiFestivalDao(IFestivalDao iFestivalDao) {
		this.iFestivalDao = iFestivalDao;
	}
	public ITargetDao getiTargetDao() {
		return iTargetDao;
	}
	public void setiTargetDao(ITargetDao iTargetDao) {
		this.iTargetDao = iTargetDao;
	}
	
	public IOPResultDto<IObjectVO> addGoods(GoodsVO goodsVO) {
		IOPResultDto<IObjectVO> dto = new IOPResultDto<IObjectVO>();
		Goods goods = new Goods();
		try {
			BeanUtils.copyProperties(goodsVO, goods);
			FlowerFlorid flowerFlorid = iFlowerFloridDao.findById(goodsVO.getFlowerFloridVO().getFlowerFloridId());
			FlowerCount flowerCount = iFlowerCountDao.findById(goodsVO.getFlowerCountVO().getFlowerCountId());
			goods.setFlowerFlorid(flowerFlorid);
			goods.setFlowerCount(flowerCount);
			int goodsId = iGoodsDao.add(goods);
			IObjectVO iObjectVO = new IObjectVO();
			List<GoodsVO> goodsVOList = new ArrayList<GoodsVO>();
			GoodsVO goodsVOReturn = new GoodsVO();
			goodsVOReturn.setGoodsId(goodsId);
			goodsVOList.add(goodsVOReturn);
			iObjectVO.setGoodsVOList(goodsVOList);
			dto.addToResultList(iObjectVO);
			dto.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			dto.setSuccess(false);
			dto.setErrorMSG(MyErrorMsgConstants.FAILED_TO_ADD_OPERATE);
		}
		return dto;
	}
	
	public IOPResultDto<IObjectVO> findAll(Integer pageNum,int pageSize) {
		IOPResultDto<IObjectVO> dto = new IOPResultDto<IObjectVO>();
		List<Goods> goodsList = new ArrayList<Goods>();
		goodsList = iGoodsDao.findAll(pageNum, pageSize);
		int totalGoodsCnt = iGoodsDao.findTotalGoodsCnt();
		List<GoodsVO> goodsVOList = new ArrayList<GoodsVO>();
		GoodsVO goodsVO = null;
		FlowerFlorid flowerFlorid = null;
		FlowerCount flowerCount = null;
		FlowerFloridVO flowerFloridVO = null;
		FlowerCountVO flowerCountVO = null;
		for (Goods goods : goodsList) {
			goodsVO = new GoodsVO();
			BeanUtils.copyProperties(goods, goodsVO);
			flowerFlorid = iFlowerFloridDao.findById(goods.getFlowerFlorid().getFlowerFloridId());
			flowerCount = iFlowerCountDao.findById(goods.getFlowerCount().getFlowerCountId());
			flowerFloridVO = new FlowerFloridVO();
			flowerCountVO = new FlowerCountVO();
			BeanUtils.copyProperties(flowerFlorid, flowerFloridVO);
			BeanUtils.copyProperties(flowerCount, flowerCountVO);
			goodsVO.setFlowerFloridVO(flowerFloridVO);
			goodsVO.setFlowerCountVO(flowerCountVO);
			goodsVOList.add(goodsVO);
		}
		IObjectVO iObjectVO = new IObjectVO();
		iObjectVO.setGoodsVOList(goodsVOList);
		iObjectVO.setTotalGoodsCnt(totalGoodsCnt);
		dto.addToResultList(iObjectVO);
		dto.setSuccess(true);
		return dto;
	}
	
	public IOPResultDto<IObjectVO> findById(Integer goodsId) {
		IOPResultDto<IObjectVO> dto = new IOPResultDto<IObjectVO>();
		Goods goods = iGoodsDao.findById(goodsId);
		GoodsVO goodsVO = new GoodsVO();
		try {
			logger.info("goodsId:"+goodsId);
			BeanUtils.copyProperties(goods, goodsVO);
			FlowerFlorid flowerFlorid = iFlowerFloridDao.findById(goods.getFlowerFlorid().getFlowerFloridId());
			FlowerCount flowerCount = iFlowerCountDao.findById(goods.getFlowerCount().getFlowerCountId());
			FlowerFloridVO flowerFloridVO = new FlowerFloridVO();
			FlowerCountVO flowerCountVO = new FlowerCountVO();
			BeanUtils.copyProperties(flowerFlorid, flowerFloridVO);
			BeanUtils.copyProperties(flowerCount, flowerCountVO);
			goodsVO.setFlowerFloridVO(flowerFloridVO);
			goodsVO.setFlowerCountVO(flowerCountVO);
			//商品产品关联
			HashMap<String, Object> goodsProductMapParam = new HashMap<String, Object>();
			goodsProductMapParam.put("goods", goods);
			List<GoodsProductMap> goodsProductMapList = iGoodsProductMapDao.findByExample(goodsProductMapParam);
			List<GoodsProductMapVO> goodsProductMapVOList = new ArrayList<GoodsProductMapVO>();
			GoodsProductMapVO goodsProductMapVO = null;
			for (GoodsProductMap goodsProductMap : goodsProductMapList) {
				goodsProductMapVO = new GoodsProductMapVO();
				BeanUtils.copyProperties(goodsProductMap, goodsProductMapVO);
				Product product = iProductDao.findById(goodsProductMap.getProduct().getProductId());
				ProductVO productVO = new ProductVO();
				BeanUtils.copyProperties(product, productVO);
				Variety variety = iVarietyDao.findById(product.getVariety().getVarietyId());
				Color color = iColorDao.findById(product.getColor().getColorId());
				VarietyVO varietyVO = new VarietyVO();
				ColorVO colorVO = new ColorVO();
				BeanUtils.copyProperties(variety, varietyVO);
				BeanUtils.copyProperties(color, colorVO);
				productVO.setVarietyVO(varietyVO);
				productVO.setColorVO(colorVO);
				goodsProductMapVO.setProductVO(productVO);
				goodsProductMapVOList.add(goodsProductMapVO);
			}
			goodsVO.setGoodsProductMapVOs(goodsProductMapVOList);
			//商品用途关联
			HashMap<String, Object> goodsPurposeMapParam = new HashMap<String, Object>();
			goodsPurposeMapParam.put("goods", goods);
			List<GoodsPurposeMap> goodsPurposeMapList = iGoodsPurposeMapDao.findByExample(goodsPurposeMapParam);
			List<GoodsPurposeMapVO> goodsPurposeMapVOList = new ArrayList<GoodsPurposeMapVO>();
			GoodsPurposeMapVO goodsPurposeMapVO = null;
			for (GoodsPurposeMap goodsPurposeMap : goodsPurposeMapList) {
				goodsPurposeMapVO = new GoodsPurposeMapVO();
				BeanUtils.copyProperties(goodsPurposeMap, goodsPurposeMapVO);
				Purpose purpose = iPurposeDao.findById(goodsPurposeMap.getPurpose().getPurposeId());
				PurposeVO purposeVO = new PurposeVO();
				BeanUtils.copyProperties(purpose, purposeVO);
				goodsPurposeMapVO.setPurposeVO(purposeVO);
				GoodsVO goodsVOTemp = new GoodsVO();
				goodsVOTemp.setGoodsId(goodsId);
				goodsPurposeMapVO.setGoodsVO(goodsVOTemp);
				goodsPurposeMapVOList.add(goodsPurposeMapVO);
			}
			goodsVO.setGoodsPurposeMapVOs(goodsPurposeMapVOList);
			//商品节日关联
			HashMap<String, Object> goodsFestivalMapParam = new HashMap<String, Object>();
			goodsFestivalMapParam.put("goods", goods);
			List<GoodsFestivalMap> goodsFestivalMapList = iGoodsFestivalMapDao.findByExample(goodsFestivalMapParam);
			List<GoodsFestivalMapVO> goodsFestivalMapVOList = new ArrayList<GoodsFestivalMapVO>();
			GoodsFestivalMapVO goodsFestivalMapVO = null;
			for (GoodsFestivalMap goodsFestivalMap : goodsFestivalMapList) {
				goodsFestivalMapVO = new GoodsFestivalMapVO();
				BeanUtils.copyProperties(goodsFestivalMap, goodsFestivalMapVO);
				Festival purpose = iFestivalDao.findById(goodsFestivalMap.getFestival().getFestivalId());
				FestivalVO purposeVO = new FestivalVO();
				BeanUtils.copyProperties(purpose, purposeVO);
				goodsFestivalMapVO.setFestivalVO(purposeVO);
				GoodsVO goodsVOTemp = new GoodsVO();
				goodsVOTemp.setGoodsId(goodsId);
				goodsFestivalMapVO.setGoodsVO(goodsVOTemp);
				goodsFestivalMapVOList.add(goodsFestivalMapVO);
			}
			goodsVO.setGoodsFestivalMapVOs(goodsFestivalMapVOList);
			//商品赠送对象关联
			HashMap<String, Object> goodsTargetMapParam = new HashMap<String, Object>();
			goodsTargetMapParam.put("goods", goods);
			List<GoodsTargetMap> goodsTargetMapList = iGoodsTargetMapDao.findByExample(goodsTargetMapParam);
			List<GoodsTargetMapVO> goodsTargetMapVOList = new ArrayList<GoodsTargetMapVO>();
			GoodsTargetMapVO goodsTargetMapVO = null;
			for (GoodsTargetMap goodsTargetMap : goodsTargetMapList) {
				goodsTargetMapVO = new GoodsTargetMapVO();
				BeanUtils.copyProperties(goodsTargetMap, goodsTargetMapVO);
				Target purpose = iTargetDao.findById(goodsTargetMap.getTarget().getTargetId());
				TargetVO purposeVO = new TargetVO();
				BeanUtils.copyProperties(purpose, purposeVO);
				goodsTargetMapVO.setTargetVO(purposeVO);
				GoodsVO goodsVOTemp = new GoodsVO();
				goodsVOTemp.setGoodsId(goodsId);
				goodsTargetMapVO.setGoodsVO(goodsVOTemp);
				goodsTargetMapVOList.add(goodsTargetMapVO);
			}
			goodsVO.setGoodsTargetMapVOs(goodsTargetMapVOList);
			
			IObjectVO iObjectVO = new IObjectVO();
			List<GoodsVO> goodsVOList = new ArrayList<GoodsVO>();
			goodsVOList.add(goodsVO);
			iObjectVO.setGoodsVOList(goodsVOList);
			dto.addToResultList(iObjectVO);
			dto.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			dto.setErrorMSG(MyErrorMsgConstants.FAILED_TO_QUERY_GOODS);
			dto.setSuccess(false);
		}
		return dto;
	}
	
	public IOPResultDto<IObjectVO> updateGoods(GoodsVO goodsVO) {
		IOPResultDto<IObjectVO> dto = new IOPResultDto<IObjectVO>();
		Goods goods = new Goods();
		try {
			BeanUtils.copyProperties(goodsVO, goods);
			FlowerFlorid flowerFlorid = iFlowerFloridDao.findById(goodsVO.getFlowerFloridVO().getFlowerFloridId());
			FlowerCount flowerCount = iFlowerCountDao.findById(goodsVO.getFlowerCountVO().getFlowerCountId());
			goods.setFlowerFlorid(flowerFlorid);
			goods.setFlowerCount(flowerCount);
			iGoodsDao.update(goods);
			dto.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			dto.setSuccess(false);
			dto.setErrorMSG(MyErrorMsgConstants.FAILED_TO_UPDATE_OPERATE);
		}
		return dto;
	}
	
	public IOPResultDto<IObjectVO> deleteById(String goodsId) {
		IOPResultDto<IObjectVO> dto = new IOPResultDto<IObjectVO>();
		try {
			Goods goods = iGoodsDao.findById(Integer.valueOf(goodsId));
			Set goodsProductMapSet = goods.getGoodsProductMaps();
			Iterator itProduct = goodsProductMapSet.iterator();
			while (itProduct.hasNext()) {
				GoodsProductMap goodsProductMap = (GoodsProductMap) itProduct.next();
				iGoodsProductMapDao.delete(goodsProductMap);
			}
			Set goodsPurposeMapSet = goods.getGoodsPurposeMaps();
			Iterator itPurpose = goodsPurposeMapSet.iterator();
			while (itPurpose.hasNext()) {
				GoodsPurposeMap goodsPurposeMap = (GoodsPurposeMap) itPurpose.next();
				iGoodsPurposeMapDao.delete(goodsPurposeMap);
			}
			Set goodsFestivalMapSet = goods.getGoodsFestivalMaps();
			Iterator itFestival = goodsFestivalMapSet.iterator();
			while (itFestival.hasNext()) {
				GoodsFestivalMap goodsFestivalMap = (GoodsFestivalMap) itFestival.next();
				iGoodsFestivalMapDao.delete(goodsFestivalMap);
			}
			Set goodsTargetMapSet = goods.getGoodsTargetMaps();
			Iterator itTarget = goodsTargetMapSet.iterator();
			while (itTarget.hasNext()) {
				GoodsTargetMap goodsTargetMap = (GoodsTargetMap) itTarget.next();
				iGoodsTargetMapDao.delete(goodsTargetMap);
			}
			iGoodsDao.delete(goods);
			dto.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			dto.setSuccess(false);
			dto.setErrorMSG(MyErrorMsgConstants.FAILED_TO_DELETE_OPERATE);
		}
		return dto;
	}
	
	public IOPResultDto<IObjectVO> findIndexGoods(String onSaleCnt, String commonCnt) {
		IOPResultDto<IObjectVO> dto = new IOPResultDto<IObjectVO>();
		try {
			List<Goods> goodsOnSaleList = iGoodsDao.findGoodsByBarginFlag(1, Integer.valueOf(onSaleCnt));
			List<Goods> goodsCommonList = iGoodsDao.findAll(1, Integer.valueOf(commonCnt));
			List<GoodsVO> goodsVOOnSaleList = new ArrayList<GoodsVO>();
			List<GoodsVO> goodsVOCommonList = new ArrayList<GoodsVO>();
			GoodsVO goodsVOOnSale = null;
			GoodsVO goodsVOCommon = null;
			for (Goods goods : goodsOnSaleList) {
				goodsVOOnSale = new GoodsVO();
				BeanUtils.copyProperties(goods, goodsVOOnSale);
				goodsVOOnSaleList.add(goodsVOOnSale);
			}
			for (Goods goods : goodsCommonList) {
				goodsVOCommon = new GoodsVO();
				BeanUtils.copyProperties(goods, goodsVOCommon);
				goodsVOCommonList.add(goodsVOCommon);
			}
			IObjectVO iObjectVO = new IObjectVO();
			iObjectVO.setGoodsVOList(goodsVOOnSaleList);
			IObjectVO iObjectVO2 = new IObjectVO();
			iObjectVO2.setGoodsVOList(goodsVOCommonList);
			dto.addToResultList(iObjectVO);
			dto.addToResultList(iObjectVO2);
			dto.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			dto.setSuccess(false);
			dto.setErrorMSG(MyErrorMsgConstants.FAILED_TO_QUERY_GOODS);
		}
		return dto;
	}
	
	public IOPResultDto<IObjectVO> findByType(Integer pageNum, Integer pageSize, String varietyId, String colorId,String purposeId, String festivalId, String targetId, Integer flowerFloridId, Integer flowerCountId) {
		IOPResultDto<IObjectVO> dto = new IOPResultDto<IObjectVO>();
		List<Goods> goodsList = iGoodsDao.finByType(pageNum, pageSize, varietyId, colorId, purposeId, festivalId, targetId, flowerFloridId, flowerCountId);
		List<GoodsVO> goodsVOList = new ArrayList<GoodsVO>();
		GoodsVO goodsVO = null;
		if(goodsList != null) {
			for (Goods goods : goodsList) {
				goodsVO = new GoodsVO();
				BeanUtils.copyProperties(goods, goodsVO);
				goodsVOList.add(goodsVO);
			}
		}
		IObjectVO iObjectVO = new IObjectVO();
		iObjectVO.setGoodsVOList(goodsVOList);
		dto.addToResultList(iObjectVO);
		dto.setSuccess(true);
		return dto;
	}
	
	public IOPResultDto<IObjectVO> findByCondition(Integer pageNum, Integer pageSize, String searchCondition) {
		IOPResultDto<IObjectVO> dto = new IOPResultDto<IObjectVO>();
		List<Goods> goodsList = iGoodsDao.finByCondition(pageNum, pageSize, searchCondition);
		List<GoodsVO> goodsVOList = new ArrayList<GoodsVO>();
		GoodsVO goodsVO = null;
		if(goodsList != null) {
			for (Goods goods : goodsList) {
				goodsVO = new GoodsVO();
				BeanUtils.copyProperties(goods, goodsVO);
				goodsVOList.add(goodsVO);
			}
		}
		IObjectVO iObjectVO = new IObjectVO();
		iObjectVO.setGoodsVOList(goodsVOList);
		dto.addToResultList(iObjectVO);
		dto.setSuccess(true);
		return dto;
	}
	public IOPResultDto<IObjectVO> findByIsBargin(Integer pageNum, int pageSize, Integer isBargin) {
		IOPResultDto<IObjectVO> dto = new IOPResultDto<IObjectVO>();
		List<Goods> goodsList = new ArrayList<Goods>();
		goodsList = iGoodsDao.findByIsBargin(pageNum, pageSize, isBargin);
		int totalGoodsCnt = iGoodsDao.findTotalGoodsCntByIsBargin(isBargin);
		List<GoodsVO> goodsVOList = new ArrayList<GoodsVO>();
		GoodsVO goodsVO = null;
		FlowerFlorid flowerFlorid = null;
		FlowerCount flowerCount = null;
		FlowerFloridVO flowerFloridVO = null;
		FlowerCountVO flowerCountVO = null;
		for (Goods goods : goodsList) {
			goodsVO = new GoodsVO();
			BeanUtils.copyProperties(goods, goodsVO);
			flowerFlorid = iFlowerFloridDao.findById(goods.getFlowerFlorid().getFlowerFloridId());
			flowerCount = iFlowerCountDao.findById(goods.getFlowerCount().getFlowerCountId());
			flowerFloridVO = new FlowerFloridVO();
			flowerCountVO = new FlowerCountVO();
			BeanUtils.copyProperties(flowerFlorid, flowerFloridVO);
			BeanUtils.copyProperties(flowerCount, flowerCountVO);
			goodsVO.setFlowerFloridVO(flowerFloridVO);
			goodsVO.setFlowerCountVO(flowerCountVO);
			goodsVOList.add(goodsVO);
		}
		IObjectVO iObjectVO = new IObjectVO();
		iObjectVO.setGoodsVOList(goodsVOList);
		iObjectVO.setTotalGoodsCnt(totalGoodsCnt);
		dto.addToResultList(iObjectVO);
		dto.setSuccess(true);
		return dto;
	}
	
	public IOPResultDto<IObjectVO> updateGoodsBarginState(GoodsVO goodsVO) {
		IOPResultDto<IObjectVO> dto = new IOPResultDto<IObjectVO>();
		Goods goods = new Goods();
		try {
			goods = iGoodsDao.findById(goodsVO.getGoodsId());
			goods.setIsBargin(goodsVO.getIsBargin());
			goods.setBarginPrice(goodsVO.getBarginPrice());
			iGoodsDao.update(goods);
			dto.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			dto.setSuccess(false);
			dto.setErrorMSG(MyErrorMsgConstants.FAILED_TO_UPDATE_OPERATE);
		}
		return dto;
	}
	
}
